<script setup>
import { ref } from "vue";
import Orchestrator from "@/logic/audioOrchestrator";
import { useStore } from '@/stores/data'
const roomid = ref("");
const text   = ref("");
const store = useStore()
function startAll() {
  // 提供获取配置 & token 的方法
  Orchestrator.init({
    getConfig: () => window.store?.userConfig || {}, // 挂到 window.store，或自行改成从 pinia 取
    getToken:  () => {
      let raw = localStorage.getItem("token") || "";
      raw = String(raw).trim();
      if (!raw || raw === "null" || raw === "undefined" || raw === "None") return "";
      return raw.toLowerCase().startsWith("bearer ")? raw : ("Bearer " + raw);
    },
    onLog: console.log
  });

  Orchestrator.unlockAudio();   // 手势解锁（请让用户点一下）
  Orchestrator.connectSynth();  // 连接合成 WS
  Orchestrator.fillMain();      // 立刻补满主话术
}
function stopAll() {
  Orchestrator.disconnectSynth();
  Orchestrator.disconnectChat();
}

function addMain()   { Orchestrator.addMain(text.value || "这是主话术示例"); }
function addEvent()  { Orchestrator.addEvent(text.value || "这是插话示例", "interrupt"); }

</script>

<template>
  <div style="padding:10px;font-size:12px">
    <button @click="store.deepseek('你好', '石富强')">测试deepseek</button>
    <div style="margin-bottom:6px">
      <button @click="startAll">▶ 启动（解锁+连接+补主）</button>
      <button @click="stopAll" style="margin-left:8px">■ 停止</button>
      <button @click="Orchestrator.fillMain()" style="margin-left:8px">补满主话术</button>
    </div>

    <div style="margin:6px 0">
      <input v-model="text" placeholder="输入文本" style="width:260px" />
      <button @click="addMain" style="margin-left:6px">主 +1</button>
      <button @click="addEvent" style="margin-left:6px">事件 +1</button>
    </div>

    <div style="margin-top:8px">
      主队列：{{ Orchestrator.state.mainList.length }}/{{ Orchestrator.state.maxMain }}，
      事件：{{ Orchestrator.state.eventList.length }}，
      播放：主 {{ Orchestrator.state.mainPlaying ? '√' : '×' }} ｜ 事 {{ Orchestrator.state.eventPlaying ? '√' : '×' }}
    </div>
  </div>
</template>
